import {
	mapMutations
} from 'vuex';
import * as index from '@/api/index.js'
export default {
	data() {
		return {
			userinfo:{},
			id:'',
			area:'', // 地址
			form:{
				userId:'',
				recipient:'', // 收货人
				mobile:'', // 手机号
				deliveryAddress:'', // 详细地址
				defaultAddress:0
			}
		}
	},
	onPageScroll(e) {
		
	},
	computed: {
	
	},
	watch: {
	
	},
	onShow() {
		this.userinfo = uni.getStorageSync('userinfo')
		this.form.userId = this.userinfo.userId
	},
	onLoad(option) {
		if(option.id) {
			this.id = option.id
			this.address_info()
		}
	},
	// 上拉触底
	onReachBottom() {

	},
	// 下拉刷新
	onPullDownRefresh() {

	},

	methods: {
		...mapMutations(['converList']),
		// 获取信息
		address_info() {
			index.deliveryAddressDetail({id:this.id}).then(res=>{
				console.log(res)
				this.form.recipient = res.deliveryAddress.recipient
				this.form.mobile = res.deliveryAddress.mobile
				this.form.deliveryAddress = res.deliveryAddress.deliveryAddress
			})
		},
		// 新增地址
		addbnt() {
			if(!this.form.recipient) {
				this.$tools.toast('请输入收货人姓名!')
				return
			}
			if(!this.form.mobile ) {
				this.$tools.toast('请输入手机号!')
				return
			}
			if(this.form.mobile.length != 11) {
				this.$tools.toast('请输入正确的手机号!')
				return
			}
			if(!this.form.deliveryAddress) {
				this.$tools.toast('请输入详细地址!')
				return
			}
			if(this.id) {
				this.form.id = this.id
				index.deliveryAddressUpdate(this.form).then(res=>{
					uni.navigateBack(-1)
				})
			} else {
				index.deliveryAddressAdd(this.form).then(res=>{
					uni.navigateBack(-1)
				})
			}
			
		},
		// 跳转
		go() {
			this.$tools.navigate('/pagesA/list/index')
			console.log('及拿来了 ')
		}
	}
}
